# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=pytz
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2018.4
pkgrel=1
pkgdesc="Cross platform time zone library for Python (mingw-w64)"
arch=('any')
url="https://pypi.python.org/pypi/pytz"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2")
#_dtoken="a4/09/c47e57fc9c7062b4e83b075d418800d322caa87ec0ac21e6308bd3a2d519"
source=(https://pypi.io/packages/source/p/pytz/pytz-${pkgver}.tar.gz{,.asc})
sha256sums=('c06425302f2cf668f1bba7a0a03f3c1d34d4ebeef2c72003da308b3947c7f749'
            'SKIP')

prepare() {
  cd "${srcdir}"
  cp -r pytz-${pkgver} build-python2
  cp -r pytz-${pkgver} build-python3
}

check(){
  cd ${srcdir}/build-python2/pytz/tests
  ${MINGW_PREFIX}/bin/python2 test_tzinfo.py
  cd ${srcdir}/build-python3/pytz/tests
  ${MINGW_PREFIX}/bin/python3 test_tzinfo.py
}

package_python3-pytz() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd ${srcdir}/build-python3
  # Fix locale https://github.com/ipython/ipython/issues/2057
  export LC_ALL=en_US.UTF-8

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -D LICENSE.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE
}

package_python2-pytz() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd ${srcdir}/build-python2
  # Fix locale https://github.com/ipython/ipython/issues/2057
  export LC_ALL=en_US.UTF-8

  # python 2 fix
  sed -i 's_#!/usr/bin/env python_#!/usr/bin/env python2_' pytz/tzfile.py

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -D LICENSE.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-pytz() {
  package_python2-pytz
}

package_mingw-w64-i686-python3-pytz() {
  package_python3-pytz
}

package_mingw-w64-x86_64-python2-pytz() {
  package_python2-pytz
}

package_mingw-w64-x86_64-python3-pytz() {
  package_python3-pytz
}
